package com.tanxiaoyao.wecon.ui;

import com.tanxiaoyao.wecon.R;
import com.tanxiaoyao.wecon.app.AppManager;
import com.tanxiaoyao.wecon.net.GlobalConnectHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

/**
 * 鼠标界面类
 *
 * @author tanxiaoyao (junlidev@gmail.com)
 * @version 2014/8/28 21:29.
 */
public class ActivityMouse extends Activity {
	// DEBUG标志
	private static final String TAG = "tanxiaoyao-activitymouse";
	private static final Boolean ISDEBUG = false;
	
	
	private View mouse_header;
	
	//按钮
	private Button startTouchBtn;
	private SeekBar mouseSensitivitySeekbar;
	private static GlobalConnectHelper globalConnectHelper;
	private static final String MOUSE_SEN = "mouse_sensitivity:";
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	if(ISDEBUG) Log.i("xiaoyao", "Mouse onCreate");
        super.onCreate(savedInstanceState);
//      Activity压栈
      AppManager.getAppManager().addActivity(this);
        this.setContentView(R.layout.activity_mouse);
        //实例化控件
        startTouchBtn = (Button) findViewById(R.id.start_touch);
        globalConnectHelper = GlobalConnectHelper.getGlobalConnector();
        //设置灵敏度初始值
        mouseSensitivitySeekbar = (SeekBar) findViewById(R.id.mouse_sensitivity_seekbar);
        mouseSensitivitySeekbar.setProgress(50);
        mouseSensitivitySeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				globalConnectHelper.sendMess(MOUSE_SEN + progress);
			}
		});
        startTouchBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// 跳转触控板界面
				Intent startTouchIntent = new Intent(ActivityMouse.this, ActivityMouseMain.class);
				startActivity(startTouchIntent);
				// 向PC重新传递灵敏度信息
				globalConnectHelper.sendMess(MOUSE_SEN + mouseSensitivitySeekbar.getProgress());
			}
		});
     // 得到标题栏View对象
		mouse_header = findViewById(R.id.no_btn_header);
		// 设置标题栏文字
		TextView mouse_header_title = (TextView) findViewById(R.id.no_btn_header_title);
		mouse_header_title.setText(R.string.elmulate_mouse);
    }


}
